import { isDisabledForm , cleanElements } from "./editElements.js";

export const createTable = (data) => {
  if (data.length !== 0) {
    let str = "";

    isDisabledForm(false);

    str = `<table>
        <tr>
          <th>Breed</th>
          <th>Image</th>
          <th><a id='sort_age'>Age<a/></th>
        </tr>
        `;

    data.forEach((element, index) => {
      str += `
                  <tr>
                      <td>${element.breed}</td>
                      <td><img src="${element.imageurl}" width="100" height="100" /></td>
                      <td>${element.age}</td>
                      <td><button id='delete_data_${index}' name='${element.id}'>delete</button></td>
                  </tr>
                `;
    });
    str += "</table>";

    document.getElementById("cats_show").innerHTML = str;
    return true;
  } else { cleanElements(); return false; }
};

export const createNotify = () => {
  document.getElementById("notifyShow").innerHTML = `
      <img id="notify" src="/img/add.png" style="width: 100px; height: 100px; position: absolute; top: 0; right: 0;">
      `;
  setTimeout(() => {
    const element = document.getElementById("notify");
    if (element) element.parentNode.removeChild(element);
  }, 2000);
};
